import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { User } from '../../../users/entities/user.entity';

/**
 * 代金券使用日志实体
 */
@Entity({ name: 'voucher_usage_logs', comment: '代金券使用日志表' })
export class VoucherUsageLog {
  @ApiProperty({ description: '使用记录ID' })
  @PrimaryGeneratedColumn({ comment: '使用记录ID' })
  id: number;

  @ApiProperty({ description: '用户ID' })
  @Column({ comment: '用户ID' })
  userId: number;

  @ApiProperty({ description: '消耗金额（单位：分）' })
  @Column({ 
    type: 'int',
    comment: '消耗的代金券金额，单位分' 
  })
  amountUsed: number;

  @ApiProperty({ description: '解锁的资源类型' })
  @Column({ 
    length: 50,
    comment: '解锁的资源类型，如course、video等' 
  })
  resourceType: string;

  @ApiProperty({ description: '资源ID' })
  @Column({ 
    nullable: true,
    comment: '解锁的资源ID' 
  })
  resourceId?: number;

  @ApiProperty({ description: '资源名称' })
  @Column({ 
    nullable: true,
    comment: '解锁的资源名称' 
  })
  resourceName?: string;

  @ApiProperty({ description: '使用描述' })
  @Column({ 
    nullable: true,
    comment: '使用代金券的描述' 
  })
  description?: string;

  @ApiProperty({ description: '使用时间' })
  @CreateDateColumn({ comment: '代金券使用时间' })
  createdAt: Date;

  // 关联用户
  @ManyToOne(() => User)
  @JoinColumn({ name: 'userId' })
  user: User;
}